package com.example.ui_demo_widget1;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.example.ui_demo_widget1.adapter.ClassRoomBuildingAdapter;
import com.example.ui_demo_widget1.pojo.ClassRoomBuilding;

import java.util.ArrayList;

public class ListVIew4Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_view2);
        ArrayList<ClassRoomBuilding> classRoomBuildings=new ArrayList<>();
        classRoomBuildings.add(new ClassRoomBuilding("文友楼","102","普通"));
        classRoomBuildings.add(new ClassRoomBuilding("文友楼","202","计算机"));
        ListView lvcontact = findViewById(R.id.lv_contact);
        lvcontact.setAdapter(new ClassRoomBuildingAdapter(this
        ,classRoomBuildings));
        lvcontact.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                ClassRoomBuilding item = (ClassRoomBuilding) lvcontact.getItemAtPosition(i);
                Toast.makeText(ListVIew4Activity.this,item.toString(),Toast.LENGTH_SHORT).show();
            }
        });
    }
}